
import api from '../../utils/api'
import {formatRichText} from '../../utils/util'
import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageBaseURL: app.imageBaseURL,
    imageResizeParams: app.imageResizeParams,
    content:'',//详情内容
    likeState:'',//点赞状态
    scState:'',
  },
  navYouthDetail(e){
    wx.navigateTo({
      url: '/pages/index_youthhome_detail/index?youthid=' + e.currentTarget.dataset.youthid,
    })
  },
  onclike(e){
    //类型，1点赞，2收藏
    let type = e.currentTarget.dataset.type;
    let id = e.currentTarget.dataset.id;
    this.getlike(id,type)
  },
  //点赞,收藏
  async getlike (id,type) {
    let data={}
    data['flag'] = 'info_like'
    data['id'] = id
    data['type'] = type
    const {recode, result, message} = await api.send(data)
    if(recode === 'SUCC') {
      this.getNewDetail(id)
    }else {
      Toast(message)
    }
  },
  //详情
  async getNewDetail (id) {
    let data={}
    data['flag'] = 'info_detail'
    data['id'] = id
    const {recode, result, message} = await api.send(data)
    if(recode === 'SUCC') {
      result.info = api.strcharacterDiscode(result.info)
      result.info = formatRichText(result.info)
      this.setData({
        content:result,
      })
    }else {
      Toast(message)
    }
  },
  //浏览器
  async lookNum(id){
    let data={}
    data['flag'] = 'info_addlooknum'
    data['id'] = id
    const {recode, result, message} = await api.send(data)
    if(recode === 'SUCC') {
      // Toast(message)
    }else {
      Toast(message)
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getNewDetail(options.id)
    this.lookNum(options.id)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // this.getUser()

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})